package org.example.sunrise.core;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public abstract class Cache<K, V> implements Function<K, V> {
    private final Map<K, V> cache = new HashMap<>();

    public V get(K key) {
        if (cache.containsKey(key)) {
            return cache.get(key);
        } else {
            V value = apply(key);
            cache.put(key, value);
            return value;
        }
    }
}
